package Hxw3DEngine.core.Resource.texture 
{
	/**
	 * ...
	 * @author lighter
	 */
	
	import flash.utils.ByteArray;
	import Hxw3DEngine.asset.parsers.texture.ATFDataVO;
	import Hxw3DEngine.proxy.Stage3DProxy;
	import flash.display3D.textures.Texture; 
	import flash.events.Event;
	 
	public class ATFTexture extends ResourceTexture 
	{
		private var _numOfLod:uint;
		
		static public function create(voAtf:ATFDataVO):ATFTexture
		{
			var texRes:ATFTexture = new ATFTexture();
			texRes.createFromVO(voAtf);
			return texRes;
		}
		
		public function ATFTexture() 
		{
			
		}
		override public function createFromVO(vo:Object):Boolean
		{
			var voAtf:ATFDataVO = vo as ATFDataVO;
			_width = voAtf.width;
			_height = voAtf.height;	
			mipmap = voAtf.numTextures>1?true:false;
			format = voAtf.format;
			_numOfLod = voAtf.numTextures;
			
			texture = Stage3DProxy.context3d.createTexture(width, height, format, false);
			if (texture == null) {
				return false;
			}
			Texture(texture).addEventListener(Event.TEXTURE_READY, async);
			Texture(texture).uploadCompressedTextureFromByteArray(voAtf.ba,0,true);
			return true;
		}
		override public function dispose():void 
		{
			super.dispose();
		}
		private function async(e:Event):void {
			trace("ATFTexture createFromVO");
		}
	}

}